import Datastore from 'nedb';
import path from 'path';

export class DBStore {
  constructor(appStorePath) {
    this._hzqc = new DataStore({filename: path.join(appStorePath, 'mb_hzqc.db'), autoload: true});
    this._kwd = new DataStore({filename: path.join(appStorePath, 'mb_kwd.db'), autoload: true});
    this._dl = new DataStore({filename: path.join(appStorePath, 'xt_dlxx.db'), autoload: true});
    this._xmxx = new DataStore({filename: path.join(appStorePath, 'xm_xx.db'), autoload: true});
    this._yktz = new DataStore({filename: path.join(appStorePath, 'xm_fxyktz.db'), autoload: true});
    this._fcd = new DataStore({filename: path.join(appStorePath, 'xm_fcd.db'), autoload: true});
    this._kjl = new DataStore({filename: path.join(appStorePath, 'xm_kjl.db'), autoload: true});
    this._zypa = new DataStore({filename: path.join(appStorePath, 'xm_zypa.db'), autoload: true});
    this._zypb = new DataStore({filename: path.join(appStorePath, 'xm_zypb.db'), autoload: true});
    this._kzk = new DataStore({filename: path.join(appStorePath, 'xm_fxkzk.db'), autoload: true});
    this._gsp = new DataStore({filename: path.join(appStorePath, 'xm_gsp.db'), autoload: true});
    this._sh = new DataStore({filename: path.join(appStorePath, 'xm_sh.db'), autoload: true});
    this._sharedCache = new DataStore({inMemoryOnly: true, autoload: true});
  }
  get hzqc() { return this._hzqc; }
  get kwd() { return this._kwd; }
  get dl() { return this._dl; }
  get xmxx() { return this._xmxx; }
  get yktz() { return this._yktz; }
  get fcd() { return this._fcd; }
  get kjl() { return this._kjl; }
  get zypa() { return this._zypa; }
  get zypb() { return this._zypb; }
  get kzk() { return this._kzk; }
  get gsp() { return this._gsp; }
  get sh() { return this._sh; }
  get sharedcache() { return this._sharedCache; }
  compactDatabases() {
    return new Promise((res, rej) => {
      this._dl.persistence.compactDatafile();
      this._xmxx.persistence.compactDatafile();
      this._yktz.persistence.compactDatafile();
      this._fcd.persistence.compactDatafile();
      this._kjl.persistence.compactDatafile();
      this._zypa.persistence.compactDatafile();
      this._zypb.persistence.compactDatafile();
      this._kzk.persistence.compactDatafile();
      this._gsp.persistence.compactDatafile();
      this._sh.persistence.compactDatafile();
      res();
    });
  }
}
